package com.gitee.huanminabc.dynamicdb.core;

import com.gitee.huanminabc.dynamicdb.common.Constants;
import com.gitee.huanminabc.dynamicdb.common.DynamicDbException;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
/**
 * @author huanmin
 * @date 2024/11/22
 */
/**
 * 默认数据源切换
 */
public class DynamicDataSource extends AbstractRoutingDataSource  {

    @Override
    protected Object determineCurrentLookupKey() {
        String currentDb = DbKeysManage.currentDbKey();
        if (currentDb == null) {
            throw new DynamicDbException("没有指定数据源");
        }
        return Constants.MULTI_DB_PREFIX +currentDb;
    }

}
